package cn.kuporo.seckill.activity.infrastructure.repository;

import cn.kuporo.seckill.activity.domain.model.SeckillActivity;
import cn.kuporo.seckill.activity.domain.repository.SeckillActivityRepository;
import cn.kuporo.seckill.activity.infrastructure.mapper.SeckillActivityMapper;
import cn.kuporo.seckill.common.exception.ErrorCode;
import cn.kuporo.seckill.common.exception.SeckillException;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * @author: kuporo
 * @since: 2025/7/7
 * @description:
 */
@Component
@RequiredArgsConstructor
public class SeckillActivityRepositoryImpl implements SeckillActivityRepository {
    private final SeckillActivityMapper seckillActivityMapper;

    @Override
    public int saveSeckillActivity(SeckillActivity seckillActivity) {
        if (seckillActivity == null){
            throw new SeckillException(ErrorCode.PARAMS_INVALID);
        }
        return seckillActivityMapper.saveSeckillActivity(seckillActivity);
    }

    @Override
    public List<SeckillActivity> getSeckillActivityList(Integer status) {
        return seckillActivityMapper.getSeckillActivityList(status);
    }

    @Override
    public List<SeckillActivity> getSeckillActivityListBetweenStartTimeAndEndTime(LocalDateTime currentTime, Integer status) {
        return seckillActivityMapper.getSeckillActivityListBetweenStartTimeAndEndTime(currentTime, status);
    }


    @Override
    public SeckillActivity getSeckillActivityById(Long id) {
        return seckillActivityMapper.getSeckillActivityById(id);
    }


    /**
     * 修改活动状态
     * @param id 活动id
     * @param status 活动状态
     */
    @Override
    public int updateStatus(Long id, Integer status) {
        return seckillActivityMapper.updateStatus(id, status);
    }
}
